package com.finger.gulimall.order.entity.vo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.web.bind.annotation.GetMapping;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ClassName OrderConfirmVo
 * @Description TODO
 * @Author finger
 * @Date 2022/7/5 9:51
 * @Version 1.0
 */

public class OrderConfirmVo {

    /**
     * 收货地址
     */
    @Getter
    @Setter
    private List<MemberReceiveAddressVo> addressVos;

    /**
     * 购物车订单项
     */
    @Getter
    @Setter
    private List<CartItemVo> cartItemVos;

    /**
     * 用户积分
     */
    @Setter
    @Getter
    private Integer integral;

    /**
     * 重量
     */
    @Getter
    @Setter
    private BigDecimal weight;

    @Setter
    @Getter
    private String token;

    /**
     * 是否有货
     */
    @Setter
    @Getter
    private Map<Long, Boolean> hasStock;

    public Integer getTotalCount() {
        Integer total = 0;
        for (CartItemVo cartItemVo : cartItemVos) {
            total += cartItemVo.getCount();
        }
        return total;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal sum = new BigDecimal("0");
        for (CartItemVo cartItemVo : cartItemVos) {
            // 获取最新查询玩完库存之后的价格
            sum = sum.add(cartItemVo.getTotalPrice());
        }

        return sum;
    }

    public BigDecimal getPayPrice(){
        return getTotalPrice();
    }
}
